/*******************************************************************************
 * Copyright (c) 2012 - 2013  Raining Ideas Pvt Ltd.
 * All rights reserved. 
 * This computer software is owned by Raining Ideas Pvt Ltd,
 * and is protected by Indian copyright laws.
 * -----------------------------------------------------------------------------
 * $Id: $
 * -----------------------------------------------------------------------------
 *******************************************************************************/
/**
 * @author Manu
 */
package de.greenrobot.daoexample;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;

public class InningzDBGenerator {

	private static Property matchId_fromPlayers;

	public InningzDBGenerator() {
		
	}
	
	public static void main(String[] args) throws Exception {
		Schema schema = new Schema(1000, "com.raining.inningz.database.dao");
		
		//wallSample(schema);
		
		
		preRulesData(schema);
		
		new DaoGenerator().generateAll(schema, "../InningzAndroid/src");
	}
	
    private static void preRulesData(Schema schema) {
	
    	 Entity item = schema.addEntity("PreRulesTable");
         
         item.addIdProperty().autoincrement();
         item.addStringProperty("Name");
         item.addIntProperty("InningzperTeam");
        
         
         
         
         item.addIntProperty("OversPerTeam");
         item.addIntProperty("OversPerBowlerPerInningz");
         item.addBooleanProperty("ExtraBallforNoball");
         item.addIntProperty("PenaltyRunsForNoball");
         
         
         item.addBooleanProperty("AllowFreeHits");
         item.addBooleanProperty("ExtraBallForWide");
         item.addIntProperty("PenaltyRunsForWide");
         item.addBooleanProperty("AllowBonusRuns");
         item.addBooleanProperty("AllowPenaltyRuns");
         item.addIntProperty("BatsmenPerTeamPerInningz");
         item.addIntProperty("BallsPerBatsmenPerInningz");
         item.addIntProperty("BallsPerOver");
	}

	private static void wallSample(Schema schema) throws Exception {
    	
    	
    
    	
    	Entity subscriptions = createTableSubscriptions(schema);
//    	Entity matchProgression = createTableMatchProgression(schema);
    	Entity matchDetails = createTableMatchDetails(schema);
    	Entity matchResults = createTableMatchResults(schema);
    	Entity actionCommentary = createTableActionCommentary(schema);
    	Entity scoreLine = createTableScoreLine(schema, actionCommentary);
    	Entity scoringTemplates = createTableScoringTemplates(schema);
    	Entity players = createTablePlayers(schema);
    	Entity battingSummary = createTableBattingSummary(schema, players);
    	Entity bowlingSummary = createTableBowlingSummary(schema, players);
    	Entity extrasSummary = createTableExtrasSummary(schema);
    	
    	Entity matchInnings = createTableMatchInnings(schema, scoreLine, extrasSummary, battingSummary, bowlingSummary);
    	Entity matches = createTableMatches(schema, subscriptions, scoringTemplates, players, matchResults, matchDetails, matchInnings);
//    	Entity scoreLineHistory = createTableScoreLineHostory(schema, scoreLine, extrasSummary, battingSummary, bowlingSummary);
    	
//    	scoreLine.addLongProperty("scoreLineHistoryId").getProperty();
//    	scoreLine.addToOne(scoreLineHistory, scoreLineHistoryId);
    	
    	Property scoreLineId = matchInnings.addLongProperty("scoreLineId").getProperty();
    	matchInnings.addToOne(scoreLine, scoreLineId);
    	
    	Property inningOfMatchId = matchInnings.addLongProperty("inningsOfMatch").getProperty();
    	matchInnings.addToOne(matches, inningOfMatchId);
    	
    	new DaoGenerator().generateAll(schema, "../InningzAndroid/src");
    	
     
       
	}
    
    /**
     * CREATE TABLE ZACTIONCOMMENTARY ( 
     * Z_PK INTEGER PRIMARY KEY, 
     * Z_ENT INTEGER, 
     * Z_OPT INTEGER, 
     * ZSEQNUM INTEGER, 
     * ZUNDEF1 INTEGER, 
     * ZSCORELINEREF INTEGER, 
     * ZTEXT VARCHAR, 
     * ZTYPE VARCHAR, 
     * ZUNDEF2 VARCHAR, 
     * ZUNDEF3 VARCHAR, 
     * ZUNDEF4 VARCHAR );
     * 
     * No foreign key
     * 
     * @param schema
     * @param scoreLine
     * @return
     */
	private static Entity createTableActionCommentary(Schema schema) {
		 Entity actionCommentary = schema.addEntity("ActionCommentary");
         actionCommentary.addIdProperty();
         actionCommentary.addLongProperty("seqNum");
         actionCommentary.addLongProperty("undef1");
         actionCommentary.addLongProperty("scoreLineRef");
         actionCommentary.addStringProperty("text");
         actionCommentary.addStringProperty("type");
         actionCommentary.addStringProperty("undef_2");
         actionCommentary.addStringProperty("undef_3");
         actionCommentary.addStringProperty("undef_4");
         return actionCommentary;
	}
	
	/**
	 * 
	 * CREATE TABLE ZBATTINGSUMMARY ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBALLNUMONDISMISSAL INTEGER, 
	 * ZBALLSFACED INTEGER, 
	 * ZBATSMANNUM INTEGER, 
	 * ZBOWLERNUM INTEGER, 
	 * ZDOTS INTEGER, 
	 * ZFEILDERNUM3 INTEGER, 
	 * ZFIELDERNUM INTEGER, 
	 * ZFIELDERNUM2 INTEGER, 
	 * ZFIVES INTEGER, 
	 * ZFOURS INTEGER, 
	 * ZONES INTEGER, 
	 * ZOTHERS INTEGER, 
	 * ZPOSITION INTEGER, 
	 * ZRUNSSCORED INTEGER, 
	 * ZSCORELINEHISTORYSW INTEGER, 
	 * ZSIXES INTEGER, 
	 * ZTHREES INTEGER, 
	 * ZTOTALONDISMISSAL INTEGER, 
	 * ZTWOS INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZWICKETSONDISMISSAL INTEGER, 
	 * ZBATTINGHISTORYFORSCORELINE INTEGER, 
	 * ZINNING INTEGER, 
	 * ZOVERSONDISMISSAL DECIMAL, 
	 * ZDISMISSALCD VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign key
	 * 
	 */
	private static Entity createTableBattingSummary(Schema schema, Entity players) {
		Entity battingSummary = schema.addEntity("BattingSummary");
		battingSummary.addIdProperty();
		battingSummary.addLongProperty("ballNumOnDismissal");
		battingSummary.addLongProperty("ballsFaced");
		Property batsMan = battingSummary.addLongProperty("batsmanNum").getProperty();
		battingSummary.addLongProperty("bowlerNum");
		battingSummary.addLongProperty("dots");
		battingSummary.addLongProperty("fielderNum3");
		battingSummary.addLongProperty("fielderNum");
		battingSummary.addLongProperty("fielderNum2");
		battingSummary.addLongProperty("fives");
		battingSummary.addLongProperty("fours");
		battingSummary.addLongProperty("ones");
		battingSummary.addLongProperty("others");
		battingSummary.addLongProperty("position");
		battingSummary.addLongProperty("runsScored");
		battingSummary.addLongProperty("scoreLineHistorysw");
		battingSummary.addLongProperty("sixes");
		battingSummary.addLongProperty("threes");
		battingSummary.addLongProperty("totalOnDismissal");
		battingSummary.addLongProperty("twos");
		battingSummary.addLongProperty("undef1");
		battingSummary.addLongProperty("uploaddsw");
		battingSummary.addLongProperty("wicketsOnDismissal");
		battingSummary.addLongProperty("battingHistoryScoreline");
		battingSummary.addLongProperty("inning");
		battingSummary.addLongProperty("oversOnDismissal");
		battingSummary.addLongProperty("dismissalcd");
		battingSummary.addLongProperty("undef2");
		battingSummary.addLongProperty("undef3");
		battingSummary.addLongProperty("undef4");
		
		battingSummary.addToOne(players, batsMan);
		
		return battingSummary;
	}
	
	/**
	 * 
	 * CREATE TABLE ZBOWLINGSUMMARY ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBALLNUM INTEGER, 
	 * ZBOWLERNUM INTEGER, 
	 * ZINPROGRESSSW INTEGER,
	 * ZNOBALLS INTEGER, 
	 * ZPOSITION INTEGER, 
	 * ZRUNS INTEGER, 
	 * ZSCORELINEHISTORYSW INTEGER, 
	 * ZUNDEF1 INTEGER,
	 * ZUPLOADEDSW INTEGER,
	 * ZWICKETS INTEGER,
	 * ZWIDES INTEGER, 
	 * ZBOWLINGHISTORYFORSCORELINE INTEGER, 
	 * ZINNING INTEGER, 
	 * ZMAIDENS DECIMAL, 
	 * ZOVERS DECIMAL, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign key
	 * 
	 */
	private static Entity createTableBowlingSummary(Schema schema, Entity players) {
		Entity bowlingSummary = schema.addEntity("BowlingSummary");
		bowlingSummary.addIdProperty();
        bowlingSummary.addLongProperty("ballNum");
        Property bowlerNum = bowlingSummary.addLongProperty("bowlerNum").getProperty();
        bowlingSummary.addLongProperty("inProgressSw");
        bowlingSummary.addLongProperty("noBalls");
        bowlingSummary.addLongProperty("position");
        bowlingSummary.addLongProperty("runs");
        bowlingSummary.addLongProperty("scoreLineHistorySw");
        bowlingSummary.addLongProperty("undef1");
        bowlingSummary.addLongProperty("uploadedSw");
        bowlingSummary.addLongProperty("wickets");
        bowlingSummary.addLongProperty("wides");
        bowlingSummary.addLongProperty("bowlingHistoryForScoreLine");
        bowlingSummary.addLongProperty("inning");
        bowlingSummary.addFloatProperty("maidens");
        bowlingSummary.addFloatProperty("overs");
        bowlingSummary.addStringProperty("undef2");
        bowlingSummary.addStringProperty("undef3");
        bowlingSummary.addStringProperty("undef4");
        
        bowlingSummary.addToOne(players, bowlerNum);
        
        return bowlingSummary;
	}
	
	/**
	 * 
	 * CREATE TABLE ZEXTRASSUMMARY ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBONUS INTEGER, 
	 * ZBYES INTEGER, 
	 * ZFIELDERNUM INTEGER, 
	 * ZHISTORYSW INTEGER, 
	 * ZLEGBYES INTEGER, 
	 * ZNOBALLS INTEGER, 
	 * ZPENALTIES INTEGER, 
	 * ZSCORELINEHISTORYSW INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZWIDES INTEGER, 
	 * ZEXTRASHISTORYFORSCORELINE INTEGER, 
	 * ZINNING INTEGER, 
	 * ZBONUSREASON VARCHAR, 
	 * ZPENALTIESREASON VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign key
	 * 
	 */
	private static Entity createTableExtrasSummary(Schema schema) {
		Entity extrasSummary = schema.addEntity("ExtrasSummary");
		extrasSummary.addIdProperty();
		extrasSummary.addLongProperty("bonus");//Bonus runs
		extrasSummary.addLongProperty("byes");//clear
//		extrasSummary.addLongProperty("fielderNum");//Players table link, wicket keeper
//		extrasSummary.addLongProperty("historySw");
		extrasSummary.addLongProperty("legByes");// runs
		extrasSummary.addLongProperty("noBalls");// number of no balls
		extrasSummary.addLongProperty("penalties");// number of penalties
//		extrasSummary.addLongProperty("scoreLineHistorySw");
		extrasSummary.addLongProperty("undef1");
		extrasSummary.addLongProperty("uploadedSw");
		extrasSummary.addLongProperty("wides");//numer of wides
//		extrasSummary.addLongProperty("extrasHistoryForScoreline").getProperty();
		extrasSummary.addLongProperty("inning");//foreign key
		extrasSummary.addStringProperty("bonusReason");
		extrasSummary.addStringProperty("penaltiesReason");
		extrasSummary.addStringProperty("undef2");
		extrasSummary.addStringProperty("undef3");
		extrasSummary.addStringProperty("undef4");
		return extrasSummary;
	}
	
	/**
	 * 
	 * CREATE TABLE ZMATCHDETAILS ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZTOSSDECISION INTEGER, 
	 * ZTOSSWONBY INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZMATCHPARENT INTEGER, 
	 * ZMATCHREFEREEFIRSTNM VARCHAR, 
	 * ZMATCHREFEREELASTNM VARCHAR, 
	 * ZUMPIREONEFIRSTNM VARCHAR, 
	 * ZUMPIREONELASTNM VARCHAR, 
	 * ZUMPIRETHREEFIRSTNM VARCHAR, 
	 * ZUMPIRETHREELASTNM VARCHAR, 
	 * ZUMPIRETWOFIRSTNM VARCHAR, 
	 * ZUMPIRETWOLASTNM VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign keys
	 * 
	 */
	private static Entity createTableMatchDetails(Schema schema) {
		Entity matchDetails = schema.addEntity("MatchDetails");
		matchDetails.addIdProperty();
		matchDetails.addStringProperty("tossDecission");
		matchDetails.addStringProperty("tossWonBy");
		matchDetails.addLongProperty("undef1");
//		matchDetails.addLongProperty("matchParent");
		matchDetails.addStringProperty("matchRefereeFirstNm");
		matchDetails.addStringProperty("matchRefereeLastNm");
		matchDetails.addStringProperty("umpireOneFirstNm");
		matchDetails.addStringProperty("umpireOneLastNm");
		matchDetails.addStringProperty("umpireTwoFirstNm");
		matchDetails.addStringProperty("umpireTwoLastNm");
		matchDetails.addStringProperty("umpireThreeFirstNm");
		matchDetails.addStringProperty("umpireThreeLastNm");
		matchDetails.addStringProperty("undef2");
		matchDetails.addStringProperty("undef3");
		matchDetails.addStringProperty("undef4");
		return matchDetails;
	}
	
	/**
	 * 
	 * CREATE TABLE ZMATCHES ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZSCORINGTEMPLATEID INTEGER, 
	 * ZSUBSCRIPTIONSEQNUM INTEGER,
	 * ZUNDEF1 INTEGER,
	 * ZMATCHADDITIONALINFO INTEGER,
	 * ZMATCHRESULTINFO INTEGER,
	 * ZSCORINGRULES INTEGER,
	 * ZUSEDSUBSCRIPTION INTEGER,
	 * ZMATCHDT TIMESTAMP,
	 * ZPROFILEDTLID FLOAT,
	 * ZSCHEDULEID FLOAT,
	 * ZHOMETEAMSHORTNM VARCHAR,
	 * ZMATCHID VARCHAR,
	 * ZMATCHPASSCODE VARCHAR,
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR, 
	 * ZVISITORSSHORTNM VARCHAR );
	 * 
	 * 
	 * Foreign keys
	 * ---------------------- 
	 * MATCHINNINGS_ID		- (1-M) - ZMATCHINNINGS
	 * ZMATCHADDITIONALINFO - (1-1) - ZMATCHDETAILS 
	 * MATCHPROGRESSION_ID	- (1-M) - ZMATCHPROGRESSION
	 * MATCHRESULTS_ID		- (1-1) - ZMATCHRESULTS
	 * SCORINGTEMPLATES_ID	- (1-1) - ZSCORINGTEMPLATES
	 * SUBSCRIPTION_ID		- (1-1) - ZSUBSCRIPTIONS
	 * 
	 * 
	 */
	private static Entity createTableMatches(Schema schema, Entity subscriptions, Entity scoringTemplates, Entity players, Entity matchResults, Entity matchDetails, Entity matchInnings) {
		Entity matches = schema.addEntity("Matches");
		matches.addIdProperty();
		matches.addLongProperty("scoringTemplateId");
		matches.addLongProperty("subscriptionSeqNum");
		matches.addLongProperty("undef1");
		Property matchDetailsId = matches.addLongProperty("matchDetailsId").getProperty();
		Property matchResultsId = matches.addLongProperty("matchResultsId").getProperty();
		Property scoringTemplatesId = matches.addLongProperty("scoringTemplatesId").getProperty();
		Property subscriptionId = matches.addLongProperty("subscriptionId").getProperty();
		matches.addDateProperty("matchDt");
		matches.addFloatProperty("profiledtlId");
		matches.addFloatProperty("scheduleId");
		matches.addStringProperty("homeTeamShortNm");
		matches.addStringProperty("matchId").unique().notNull();
		matches.addStringProperty("matchPassCode");
		matches.addStringProperty("undef2");
		matches.addStringProperty("undef3");
		matches.addStringProperty("undef4");
		matches.addStringProperty("visitorsShortNm");
//		Property playersId = matches.addLongProperty("playersId").getProperty();
//		Property matchProgressionId = matches.addLongProperty("matchProgressionId").getProperty();
		Property matchInningzId = matches.addLongProperty("matchInningzId").getProperty();
		
		//Foreign keys
		matches.addToOne(subscriptions, subscriptionId);
		matches.addToOne(scoringTemplates, scoringTemplatesId);
		matches.addToMany(players, matchId_fromPlayers);
		matches.addToOne(matchResults, matchResultsId);
//		matches.addToMany(matchProgression, matchProgressionId);
		matches.addToOne(matchDetails, matchDetailsId);
		matches.addToMany(matchInnings, matchInningzId);
		
		return matches;
	}
	
	/**
	 * 
	 * CREATE TABLE ZMATCHINNINGS ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBATTINGTEAMNUM INTEGER, 
	 * ZBOWLINGTEAMNUM INTEGER, 
	 * ZINPROGRESSSW INTEGER, 
	 * ZINNINGNUM INTEGER, 
	 * ZLASTBALLNUM INTEGER, 
	 * ZLASTBALLNUMSEQ INTEGER, 
	 * ZSEQNUM INTEGER, 
	 * ZTOTAL INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZWICKETS INTEGER, 
	 * ZINNINGSOFMATCH INTEGER, 
	 * ZOVERS DECIMAL, 
	 * ZENDREASONCD VARCHAR, 
	 * ZENDREASONDESC VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * Foreign Keys
	 * ---------------
	 * SCORELINE_ID 		- (1-M) - SCORELINE
	 * EXTRASSUMMARY_ID 	- (1-M) - EXTRASSUMMARY
	 * BATTINGSUMMARY_ID	- (1-M) - BATTINGSUMMARY
	 * BOWLINGSUMMARY_ID	- (1-M) - BOWLINGSUMMARY
	 * 
	 */
	private static Entity createTableMatchInnings(Schema schema, Entity scoreLine, Entity extrasSummary, Entity battingSummary, Entity bowlingSummary) {
		Entity matchInnings = schema.addEntity("MatchInnings");
		matchInnings.addIdProperty();
		matchInnings.addLongProperty("battingTeamNum");
		matchInnings.addLongProperty("bowlingTeamNum");
		matchInnings.addBooleanProperty("inProgress");
		matchInnings.addLongProperty("inningNum");
		matchInnings.addLongProperty("lastBallNum");
		matchInnings.addLongProperty("lastBallNumSeq");
		matchInnings.addLongProperty("seqNum");
		matchInnings.addLongProperty("total");
		matchInnings.addLongProperty("undef1");
		matchInnings.addLongProperty("uploadedSw");
		matchInnings.addLongProperty("wickets");
//		matchInnings.addLongProperty("inningsOfMatch");
		matchInnings.addFloatProperty("overs");
		matchInnings.addStringProperty("endReasonCd");
		matchInnings.addStringProperty("endReasonDesc");
		matchInnings.addStringProperty("undef2");
		matchInnings.addStringProperty("undef3");
		matchInnings.addStringProperty("undef4");
		Property scorelineId = matchInnings.addLongProperty("scorelineId").getProperty();
		Property extrasSummaryId = matchInnings.addLongProperty("matchInningExtrasSummaryId").getProperty();
		Property matchInningBattingSummaryId = matchInnings.addLongProperty("matchInningBattingSummaryId").getProperty();
		Property matchInningBowlingSummaryId = matchInnings.addLongProperty("matchInningBowlingSummaryId").getProperty();
		
		//Foreign Keys
		matchInnings.addToMany(scoreLine, scorelineId);
		matchInnings.addToMany(extrasSummary, extrasSummaryId);
		matchInnings.addToMany(battingSummary, matchInningBattingSummaryId);
		matchInnings.addToMany(bowlingSummary, matchInningBowlingSummaryId);
		
		return matchInnings;
	}
	
	
	/**
	 * 
	 * CREATE TABLE ZSCORELINE ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBALLNUM INTEGER, 
	 * ZBALLNUMSEQ INTEGER, 
	 * ZBATSMANNUM INTEGER, 
	 * ZBOWLERNUM INTEGER, 
	 * ZDISMISSEDBATSMANNUM INTEGER, 
	 * ZEXTRASBOWLED INTEGER, 
	 * ZEXTRASSCORED INTEGER, 
	 * ZFIELDERNUM INTEGER, 
	 * ZFIELDERNUM2 INTEGER, 
	 * ZFIELDERNUM3 INTEGER, 
	 * ZNONSTRIKERBATSMANNUM INTEGER, 
	 * ZRUNSSCORED INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZHISTORY INTEGER, 
	 * ZINNINGINPROGRESS INTEGER, 
	 * ZBATSMANACTIONCD VARCHAR, 
	 * ZBOWLERACTIONCD VARCHAR, 
	 * ZDISMISSALCD VARCHAR, 
	 * ZFIELDERACTIONCD VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * CREATE INDEX ZSCORELINE_ZHISTORY_INDEX ON ZSCORELINE (ZHISTORY);
	 * CREATE INDEX ZSCORELINE_ZINNINGINPROGRESS_INDEX ON ZSCORELINE (ZINNINGINPROGRESS);
	 * 
	 * Foreign Keys
	 * --------------------
	 * ACTIONCOMMENTARY_ID	- (1-M) - ACTIONCOMMENTARY
	 * SCORELINEHISTORY_ID	- (1-1) - SCORELINEHISTORY
	 * 
	 * MATCHINNINGS_ID		- (1-1) - MATCHINNINGS  (in reverse order it's 1-ms)
	 * 
	 * 
	 */
	private static Entity createTableScoreLine(Schema schema, Entity actionCommentary) {
		Entity scoreLine = schema.addEntity("ScoreLine");
        scoreLine.addIdProperty();
        scoreLine.addLongProperty("ballNum");
        scoreLine.addLongProperty("ballNumSeq");
        scoreLine.addLongProperty("batsmanNum");
        scoreLine.addLongProperty("bowlerNum");
        scoreLine.addLongProperty("dismissedBatsmanNum");
        scoreLine.addLongProperty("extrasBowled");
        scoreLine.addLongProperty("extrasScored");
        scoreLine.addLongProperty("fielderNum");
        scoreLine.addLongProperty("fielderNum2");
        scoreLine.addLongProperty("fielderNum3");
        scoreLine.addLongProperty("nonStrikerBatsmanNum");
        scoreLine.addLongProperty("runsScored");
        scoreLine.addLongProperty("undef1");
        scoreLine.addLongProperty("uploadedSw");
        Property history = scoreLine.addLongProperty("history").getProperty();
        Property inningInProgress = scoreLine.addLongProperty("inningInProgress").getProperty();
        scoreLine.addLongProperty("batsmanActionCd");
        scoreLine.addLongProperty("bowlerActionCd");
        scoreLine.addLongProperty("dismissalCd");
        scoreLine.addLongProperty("fielderActionCd");
        scoreLine.addStringProperty("undef2");
        scoreLine.addStringProperty("undef3");
        scoreLine.addStringProperty("undef4");
        Property actionCommentaryId = scoreLine.addLongProperty("actionCommentaryId").getProperty();
        
        //Foreign Keys
        scoreLine.addToMany(actionCommentary, actionCommentaryId);
        
        return scoreLine;
	}
	
	
	
	/**
	 * CREATE TABLE ZMATCHPROGRESSION ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZSORTSEQ INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZMATCHINPROGRESS INTEGER, 
	 * ZDETAILEDDESC VARCHAR, 
	 * ZMAINDESC VARCHAR, 
	 * ZPROGRESSIONCD VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No Foreign key
	 * 
	 * can be removed
	 * 
	 */
//	private static Entity createTableMatchProgression(Schema schema) {
//		 Entity matchProgression = schema.addEntity("MatchProgression");
//		 matchProgression.addIdProperty();
//		 matchProgression.addLongProperty("sortSeq");
//		 matchProgression.addLongProperty("undef1");
//		 matchProgression.addLongProperty("uploadedSw");
//		 matchProgression.addLongProperty("matchInProgress");
//		 matchProgression.addStringProperty("detailedDesc");
//		 matchProgression.addStringProperty("mainDesc");
//		 matchProgression.addStringProperty("progressionCd");
//		 matchProgression.addStringProperty("undef2");
//		 matchProgression.addStringProperty("undef3");
//		 matchProgression.addStringProperty("undef4");
//		 return matchProgression;
//	}
	
	/**
	 * 
	 * CREATE TABLE ZMATCHRESULTS ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZMOM INTEGER, 
	 * ZMOM2 INTEGER, 
	 * ZMOM2TEAMNUM INTEGER, 
	 * ZMOMTEAMNUM INTEGER, 
	 * ZSHORTENEDSW INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZWINNER INTEGER, 
	 * ZMATCHRESULTPARENT INTEGER, 
	 * ZRESULTCD VARCHAR, 
	 * ZRESULTTEXT VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign keys
	 * 
	 */
	private static Entity createTableMatchResults(Schema schema) {
		 Entity matchResults = schema.addEntity("MatchResults");
		 matchResults.addIdProperty();
		 matchResults.addLongProperty("mom");
		 matchResults.addLongProperty("mom2");
		 matchResults.addLongProperty("mom2TeamNum");
		 matchResults.addLongProperty("momTeamNum");
		 matchResults.addLongProperty("shortenedSw");
		 matchResults.addLongProperty("undef1");
		 matchResults.addLongProperty("uploadedSw");
		 matchResults.addLongProperty("winner");
		 matchResults.addLongProperty("matchResultParent");
		 matchResults.addStringProperty("resultCd");
		 matchResults.addStringProperty("resultText");
		 matchResults.addStringProperty("undef2");
		 matchResults.addStringProperty("undef3");
		 matchResults.addStringProperty("undef4");
		 return matchResults;
	}
	
	/**
	 * 
	 * CREATE TABLE ZPLAYERS ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZBATSMANSW INTEGER, 
	 * ZBATTINGSEQ INTEGER, 
	 * ZBOWLERSW INTEGER, 
	 * ZCAPTAINSW INTEGER, 
	 * ZPLAYERNUM INTEGER, 
	 * ZSUBSW INTEGER, 
	 * ZTEAMNUM INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUPLOADEDSW INTEGER, 
	 * ZWKSW INTEGER, 
	 * ZBELONGSTOTEAM INTEGER, 
	 * ZFANCYNUM VARCHAR, 
	 * ZFIRSTNM VARCHAR, 
	 * ZLASTNM VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * 
	 * No foreign keys as for now !
	 * MATCH_ID
	 * 
	 * teamNum field have static values to be marked visiting or hosting teams.
	 *  1 - Hosting Team
	 *  2 - Visiting Team
	 * 
	 */
	private static Entity createTablePlayers(Schema schema) {
		 Entity players = schema.addEntity("Player");
		 players.addIdProperty();
		 players.addBooleanProperty("batsmanSw");
		 players.addLongProperty("battingSeq");
		 players.addBooleanProperty("bowlerSw");
		 players.addBooleanProperty("captainSw");
		 players.addLongProperty("playerNum");
		 players.addBooleanProperty("subSw");
		 players.addLongProperty("teamNum");
		 players.addLongProperty("undef1");
		 players.addLongProperty("uploadedSw");
		 players.addBooleanProperty("wkSw");
		 matchId_fromPlayers = players.addLongProperty("matchId").notNull().getProperty();
		 players.addStringProperty("fancyNum");
		 players.addStringProperty("firstName");
		 players.addStringProperty("lastName");
		 players.addStringProperty("undef2");
		 players.addStringProperty("undef3");
		 players.addStringProperty("undef4");
		 return players;
	}
	
	/**
	 * 
	 * CREATE TABLE ZSCORELINEHISTORY ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZLASTBALLNUM INTEGER, 
	 * ZLASTBALLNUMSEQ INTEGER, 
	 * ZTOTAL INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZWICKETS INTEGER, 
	 * ZASOFSCORELINE INTEGER, 
	 * ZOVERS DECIMAL, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * Foreign Keys
	 * -----------------
	 * SCORELINE_ID 		- (1-1) - SCORELINE
	 * EXTRASSUMMARY_ID 	- (1-M) - EXTRASSUMMARY
	 * BATTINGSUMMARY_ID	- (1-M) - BATTINGSUMMARY
	 * BOWLINGSUMMARY_ID	- (1-M) - BOWLINGSUMMARY
	 * 
	 */
//	private static Entity createTableScoreLineHostory(Schema schema, Entity scoreLine, Entity extrasSummary, Entity battingSummary, Entity bowlingSummary) {
//		Entity scoreLineHistory = schema.addEntity("ScoreLineHostory");
//		scoreLineHistory.addIdProperty();
//		scoreLineHistory.addLongProperty("lastBallNum");
//		scoreLineHistory.addLongProperty("lastBallNumSeq");
//		scoreLineHistory.addLongProperty("total");
//		scoreLineHistory.addLongProperty("undef1");
//		scoreLineHistory.addLongProperty("wickets");
//		scoreLineHistory.addFloatProperty("overs");
//		scoreLineHistory.addStringProperty("undef2");
//		scoreLineHistory.addStringProperty("undef3");
//		scoreLineHistory.addStringProperty("undef4");
//		Property scoreLineId = scoreLineHistory.addLongProperty("scoreLineId").getProperty();
//		Property extrasSummaryId = scoreLineHistory.addLongProperty("scoreLineExtrasSummaryId").getProperty();
//		Property battingSummaryId = scoreLineHistory.addLongProperty("scoreLineBattingSummaryId").getProperty();
//		Property bowlingSummaryId = scoreLineHistory.addLongProperty("scoreLineBowlingSummaryId").getProperty();
//		
//		//Foreign Keys
//		scoreLineHistory.addToOne(scoreLine, scoreLineId);
//		scoreLineHistory.addToMany(extrasSummary, extrasSummaryId);
//		scoreLineHistory.addToMany(battingSummary, battingSummaryId);
//		scoreLineHistory.addToMany(bowlingSummary, bowlingSummaryId);
//		return scoreLineHistory;
//	}
	
	
	/**
	 * 
	 * CREATE TABLE ZSCORINGTEMPLATES ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZALLOWBONUS INTEGER, 
	 * ZALLOWFREEHIT INTEGER, 
	 * ZALLOWPENALTIES INTEGER, 
	 * ZBALLSPERBATSMAN INTEGER, 
	 * ZBALLSPERBOWLER INTEGER, 
	 * ZBALLSPERNOBALL INTEGER, 
	 * ZBALLSPEROVER INTEGER, 
	 * ZBALLSPERWIDE INTEGER, 
	 * ZINNINGSPERTEAM INTEGER, 
	 * ZOVERSPERINNING INTEGER, 
	 * ZRUNSPERNOBALL INTEGER, 
	 * ZRUNSPERWIDE INTEGER, 
	 * ZTEMPLATEID INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUNDEF7 INTEGER, 
	 * ZMATCHSCORING INTEGER, 
	 * ZUNDEF5 DECIMAL, 
	 * ZUNDEF6 DECIMAL, 
	 * ZTEMPLATENAME VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No foreign keys
	 * 
	 */
	private static Entity createTableScoringTemplates(Schema schema) {
		 Entity scoringTemplates = schema.addEntity("ScoringTemplates");
		 scoringTemplates.addIdProperty();
		 scoringTemplates.addBooleanProperty("allowBonus");
		 scoringTemplates.addBooleanProperty("allowFreehit");
		 scoringTemplates.addBooleanProperty("allowPenalties");
		 scoringTemplates.addLongProperty("ballsPerBatsman");
		 scoringTemplates.addLongProperty("ballsPerBowler");
		 scoringTemplates.addLongProperty("ballsPerNoBall");
		 scoringTemplates.addLongProperty("ballsPerOver");
		 scoringTemplates.addLongProperty("ballsPerWide");
		 scoringTemplates.addLongProperty("inningsPerTeam");
		 scoringTemplates.addLongProperty("oversPerInning");
		 scoringTemplates.addLongProperty("overPerBowler");
		 scoringTemplates.addBooleanProperty("extraBallForNoBall");
		 scoringTemplates.addBooleanProperty("extraBallForWide");
		 scoringTemplates.addLongProperty("batsmanPerInnings");
		 scoringTemplates.addLongProperty("runsPerNoBall");
		 scoringTemplates.addLongProperty("runsPerWide");
		 scoringTemplates.addLongProperty("templateId");
		 scoringTemplates.addLongProperty("undef1");
		 scoringTemplates.addLongProperty("undef7");
		 scoringTemplates.addLongProperty("matchScoring");
		 scoringTemplates.addFloatProperty("undef5");
		 scoringTemplates.addFloatProperty("undef6");
		 scoringTemplates.addStringProperty("templateName");
		 scoringTemplates.addStringProperty("undef2");
		 scoringTemplates.addStringProperty("undef3");
		 scoringTemplates.addStringProperty("undef4");
		 return scoringTemplates;
	}
	
	
	/**
	 * 
	 * CREATE TABLE ZSUBSCRIPTIONS ( 
	 * Z_PK INTEGER PRIMARY KEY, 
	 * Z_ENT INTEGER, 
	 * Z_OPT INTEGER, 
	 * ZSEQNUM INTEGER, 
	 * ZUNDEF1 INTEGER, 
	 * ZUSEDSW INTEGER, 
	 * ZUSEDMATCHES INTEGER, 
	 * ZPURCHASEDT TIMESTAMP, 
	 * ZREFNUM VARCHAR, 
	 * ZUNDEF2 VARCHAR, 
	 * ZUNDEF3 VARCHAR, 
	 * ZUNDEF4 VARCHAR );
	 * 
	 * No Foreign keys
	 * 
	 */
	private static Entity createTableSubscriptions(Schema schema) {
		 Entity subscriptions = schema.addEntity("Subscriptions");
		 subscriptions.addIdProperty();
		 subscriptions.addLongProperty("seqNum");
		 subscriptions.addLongProperty("undef1");
		 subscriptions.addLongProperty("usedSw");
		 subscriptions.addLongProperty("usedMatches");
		 subscriptions.addDateProperty("purchaseDt");
		 subscriptions.addStringProperty("refNum");
		 subscriptions.addStringProperty("undef2");
		 subscriptions.addStringProperty("undef3");
		 subscriptions.addStringProperty("undef4");
		 return subscriptions;
	}
	
}
